package net.realsee.controller.wcs.intf;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import net.realsee.common.annotation.Log;
import net.realsee.common.annotation.RepeatSubmit;
import net.realsee.common.enums.BusinessType;
import net.realsee.common.utils.poi.ExcelUtil;
import net.realsee.domain.wcs.intf.bo.WcsIntfDataBo;
import net.realsee.domain.wcs.intf.vo.WcsIntfDataVo;
import net.realsee.framework.core.controller.BaseController;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.domain.R;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.validate.AddGroup;
import net.realsee.framework.core.validate.EditGroup;
import net.realsee.service.wcs.intf.IWcsIntfDataService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 接口中大数据包
 *
 * @author realsee
 * @date 2023-08-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wcs/intfData")
public class WcsIntfDataController extends BaseController {

    private final IWcsIntfDataService iWcsIntfDataService;

    /**
     * 查询接口中大数据包列表
     */
    @SaCheckPermission("wcs:intfData:list")
    @GetMapping("/list")
    public TableDataInfo<WcsIntfDataVo> list(WcsIntfDataBo bo, PageQuery pageQuery) {
        return iWcsIntfDataService.selectVoPage(bo, pageQuery);
    }

    /**
     * 导出接口中大数据包列表
     */
    @SaCheckPermission("wcs:intfData:export")
    @Log(title = "接口中大数据包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WcsIntfDataBo bo, HttpServletResponse response) {
        List<WcsIntfDataVo> list = iWcsIntfDataService.selectVoList(bo);
        ExcelUtil.exportExcel(list, "接口中大数据包", WcsIntfDataVo.class, response);
    }

    /**
     * 获取接口中大数据包详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wcs:intfData:query")
    @GetMapping("/{id}")
    public R<WcsIntfDataVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long id) {
        return R.ok(iWcsIntfDataService.selectVoById(id));
    }

    /**
     * 新增接口中大数据包
     */
    @SaCheckPermission("wcs:intfData:add")
    @Log(title = "接口中大数据包", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WcsIntfDataBo bo) {
        return toAjax(iWcsIntfDataService.insertByBo(bo));
    }

    /**
     * 修改接口中大数据包
     */
    @SaCheckPermission("wcs:intfData:edit")
    @Log(title = "接口中大数据包", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WcsIntfDataBo bo) {
        return toAjax(iWcsIntfDataService.updateByBo(bo));
    }

    /**
     * 删除接口中大数据包
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wcs:intfData:remove")
    @Log(title = "接口中大数据包", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iWcsIntfDataService.deleteWithValidByIds(Arrays.asList(ids)));
    }
}
